/**
 * 
 */
package vwg.na.vwm.rh.modulo.managedbeans;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlPanelGroup;

import org.primefaces.context.RequestContext;

import vwg.na.vwm.rh.motorsdk.util.componentes.RHBotonAccion;

/**
 * @author dzmncvg
 * 
 */
@ManagedBean(name="botonesMB")
@SessionScoped
public class BotonesMB implements Serializable {

	private static final long serialVersionUID = -1726112192257067058L;

	private static final String PANEL_GP_BOTONES = "panelGroupBotones";

	transient private HtmlPanelGroup panelGroup;

	@PostConstruct
	public void inicializar() {
		setPanelGroup(new HtmlPanelGroup());
	}

	// Getters & Setters
	public HtmlPanelGroup getPanelGroup() {
		return panelGroup;
	}

	public void setPanelGroup(HtmlPanelGroup panelGroup) {
		this.panelGroup = panelGroup;
	}

	public void agregarBoton(RHBotonAccion boton) {
		getPanelGroup().getChildren().add(boton);
		updateComponent(boton.getId());
		updatePanel();
	}

	private void updatePanel() {
		RequestContext.getCurrentInstance().update(PANEL_GP_BOTONES);
	}

	private void updateComponent(final String id) {
		RequestContext.getCurrentInstance().update(id);
	}

}
